package com.amit.hibernate;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class Client4 {

	public static void main(String[] args) {
		
		SessionFactory sessionfactory=ChibernateUtil.getfactory();
		Session session=sessionfactory.openSession();
		Transaction tx=session.beginTransaction();
		
		Customer cust=(Customer)session.load(Customer.class, 1);
		System.out.println("Customer info");
		System.out.println(cust.getCid()+" "+cust.getCname()+" "+cust.getEmail()+" "+cust.getPhone());
		
		CreditCard cc=cust.getCcard();
		System.out.println("cc info");
		System.out.println(cc.getCcid()+" "+cc.getCcno()+" "+cc.getCode()+" "+cc.getCtype());
		
		Set<Order> ods=cust.getOrders();
		System.out.println("order info");
		
		for(Order o:ods)
		{
			System.out.println("Order info");
			
			System.out.println(o.getOrderId()+" "+o.getTotalQty()+" "+o.getTotalCost()+" "+o.getStatus());
		
			ShippingAddress add=o.getAddress();
			System.out.println("Shipping address:"+o.getOrderId());
			System.out.println(add.getAddid()+" "+add.getStreet()+" "+add.getCity()+" "+add.getState());
		
			Set<OrderItem> items=o.getOrderItems();
			System.out.println("Order Items:"+" "+o.getOrderId());
			
			for(OrderItem oit:items)
			{
				System.out.println(oit.getOtid()+" "+oit.getCost()+" "+oit.getQty()+" "+oit.getBook().getBid());
			}
		
		
		
		}
		
		
		
		
		tx.commit();
		session.close();

	}

}
